package com.ccdt.tv.roundprogram.view.custom;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.ccdt.tv.roundprogram.R;


/**
 * Created by yangbolin on 2018/2/6.
 */

public class DialogNetWorkErrorMessage extends Dialog {

    protected View mView;
    private DialogNetWorkErrorMessage.CallBack mCallBack;


    @Override
    public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
                mCallBack.onDisMiss();
                return true;
            case KeyEvent.KEYCODE_DPAD_UP:
                mCallBack.onUp();
                return true;
            case KeyEvent.KEYCODE_DPAD_DOWN:
                mCallBack.onDown();
                return true;
        }
        return true;
    }


    public static abstract class CallBack {

        public void onDisMiss() {

        }

        public void onUp() {
        }

        public void onDown() {
        }
    }

    public DialogNetWorkErrorMessage(Context context, String msg, DialogNetWorkErrorMessage.CallBack callBack) {
        super(context);
        initView(context, msg);
        mCallBack = callBack;
    }


    private void initView(Context context, String msg) {
        mView = LayoutInflater.from(context).inflate(R.layout.view_dialog_errormessage, null);
        requestWindowFeature(Window.DECOR_CAPTION_SHADE_LIGHT);
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        setContentView(mView);
        TextView tvMsg = (TextView) mView.findViewById(R.id.tv_error_msg);
        tvMsg.setText(msg);
    }


}

